package com.dwyinyuan.enums;

import com.dwyinyuan.model.FileDTO;
import com.dwyinyuan.producer.file.BiibProducer;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.concurrent.BlockingQueue;

@Getter
@AllArgsConstructor
public enum FileProviderEnums {
    BI_IB("彼爱", "BiibProducer") {
        @Override
        public Runnable getProviderClass(BlockingQueue<FileDTO> blockingQueue) {
            return new BiibProducer(getName(), blockingQueue);
        }
    },
    ;

    private String desc;//描述
    private String name;//生产者名称


    //获取生产者实例
    public abstract Runnable getProviderClass(BlockingQueue<FileDTO> blockingQueue);

    //根据生产者名称获取枚举对象
    public static FileProviderEnums getEnumByName(String name) {
        return Arrays.stream(FileProviderEnums.values())
                .filter(c -> c.getName().equals(name))
                .findFirst()
                .get();
    }

    //根据生产者名称获取任务
    public static Runnable getTaskByName(String name, BlockingQueue<FileDTO> blockingQueue) {
        return getEnumByName(name).getProviderClass(blockingQueue);
    }
}
